<?php

namespace Game\Api;

use PhalApi\Api;


/**
 * 刷td click接口重构
 *   @desc 上传查询的数据接口
 */
class IdfaTd extends Api
{

    public function getRules()
    {
        return array(
            'click' => array(
                'idfa' => array('name' => 'idfa', 'type' => 'string',  'require' => true, 'desc' => 'idfa'),
                'source' => array('name' => 'source', 'type' => 'string',  'require' => false, 'desc' => 'source'),
                'appid' => array('name' => 'appid', 'type' => 'string',  'require' => true, 'desc' => 'appid'),
                'uid' => array('name' => 'uid', 'type' => 'string',  'require' => true, 'desc' => 'uid'),
                'ip' => array('name' => 'ip', 'type' => 'string',  'require' => true, 'desc' => 'ip'),
                'device' => array('name' => 'device', 'type' => 'string',  'require' => true, 'desc' => 'device'),
                'os' => array('name' => 'os', 'type' => 'string',  'require' => true, 'desc' => 'os'),
                'keyword' => array('name' => 'keyword', 'type' => 'string',  'require' => false, 'desc' => 'keyword'),
                'udid' => array('name' => 'udid', 'type' => 'string',  'require' => true, 'desc' => 'udid'),
                'callback' => array('name' => 'callback', 'type' => 'string',  'require' => false, 'desc' => 'callback'),
                'mac' => array('name' => 'mac', 'type' => 'string',  'require' => false, 'desc' => 'mac'),
            ),
        );
    }


    /**
     * 取手机号接口
     * @desc 取手机号接口
     * @return array data 被查数据
     * @exception 400 非法请求，参数传递错误
     */
    public function click()
    {
        // 最简单的处理方式
        header('Access-Control-Allow-Origin: *');
        header('Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS');
        header('Access-Control-Allow-Headers: *');

        $save = array();
        foreach ($this as $key => $v) {
            if ($v) {
                $save[$key] = $v;
            }
        }
        $save['source']="meizh";
        $save['callback'] = "http://api.wenfree.cn/?s=App.IdfaTdCallback.Url&idfa".$save['idfa'];

        $curl = new \PhalApi\CUrl();
        $o = "";
        foreach ($save as $k => $v) {
            $o .= "$k=" . urlencode($v) . "&";
        }
        $o = substr($o, 0, -1);
        $Url = 'http://118.190.152.171/channel/click.html';
        $Url = $Url . "?" . $o;

        $resdata = $curl->get( $Url ,6000);
        return json_decode($resdata);
    }


}
